package com.ia.aistream.controller.operating;

import java.util.List;

import com.ia.aistream.common.annotation.Log;
import com.ia.aistream.model.operating.entity.DocAppendix;
import com.ia.aistream.service.operating.IDocAppendixService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ia.aistream.common.enums.BusinessType;

import com.ia.aistream.common.core.controller.BaseController;
import com.ia.aistream.common.core.domain.AjaxResult;
import com.ia.aistream.common.utils.poi.ExcelUtil;
import com.ia.aistream.common.core.page.TableDataInfo;

/**
 * 附录信息表Controller
 * 
 * @author aistream
 * @date 2021-01-25
 */
@Controller
@RequestMapping("/aistream/appendix")
public class DocAppendixController extends BaseController
{
    private String prefix = "aistream/appendix";

    @Autowired
    private IDocAppendixService docAppendixService;

    @RequiresPermissions("aistream:appendix:view")
    @GetMapping()
    public String appendix()
    {
        return prefix + "/appendix";
    }

    /**
     * 查询附录信息表列表
     */
    @RequiresPermissions("aistream:appendix:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DocAppendix docAppendix)
    {
        startPage();
        List<DocAppendix> list = docAppendixService.selectDocAppendixList(docAppendix);
        return getDataTable(list);
    }

    /**
     * 导出附录信息表列表
     */
    @RequiresPermissions("aistream:appendix:export")
    @Log(title = "附录信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DocAppendix docAppendix)
    {
        List<DocAppendix> list = docAppendixService.selectDocAppendixList(docAppendix);
        ExcelUtil<DocAppendix> util = new ExcelUtil<DocAppendix>(DocAppendix.class);
        return util.exportExcel(list, "appendix");
    }

    /**
     * 新增附录信息表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存附录信息表
     */
    @RequiresPermissions("aistream:appendix:add")
    @Log(title = "附录信息表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DocAppendix docAppendix)
    {
        return toAjax(docAppendixService.insertDocAppendix(docAppendix));
    }

    /**
     * 修改附录信息表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DocAppendix docAppendix = docAppendixService.selectDocAppendixById(id);
        mmap.put("docAppendix", docAppendix);
        return prefix + "/edit";
    }

    /**
     * 修改保存附录信息表
     */
    @RequiresPermissions("aistream:appendix:edit")
    @Log(title = "附录信息表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DocAppendix docAppendix)
    {
        return toAjax(docAppendixService.updateDocAppendix(docAppendix));
    }

    /**
     * 删除附录信息表
     */
    @RequiresPermissions("aistream:appendix:remove")
    @Log(title = "附录信息表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(docAppendixService.deleteDocAppendixByIds(ids));
    }
}
